package utils;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * List of connections (used by servers)
 */
public class ConnectionList {

	private HashMap<String,IConnection> connections;

	
	public ConnectionList () {
		this.connections = new HashMap<String,IConnection> ();
	}
	
	
	public void addConnection (String username, IConnection connectionThread) {
		connections.put(username,connectionThread);
	}

	public IConnection getConnection (String username) {
		return connections.get (username);
	}
	
	public void removeConnection (String username) {
		connections.remove (username);
	}
	
	public int size () {
		return connections.size();
	}
	
	/**
	* Returns only the connections without the username/key - in use when server wants to send a message to all
	* the connected threads
	*/
	public ArrayList<IConnection> getConnectionsList() {
		ArrayList<IConnection> connList = new ArrayList<IConnection>(connections.values());
		return connList;
	}
}
